﻿using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Vision.Modules;
using Vision.Modules.ImageLoad;
using Vision.ModuleTool;
using VisionDesigner;

namespace Vision.VControl
{
    /// <summary>
    /// FlowNode.xaml 的交互逻辑
    /// </summary>
    public partial class FlowNode : UserControl
    {
        // 创建用户控件自定义属性
        [Category("节点名")]
        public string FlowName
        {
            get
            {
                return lblTitle.Content?.ToString() ?? string.Empty;
            }
            set
            {
                if (value == null)
                {
                    lblTitle.Content = string.Empty;
                }
                else
                {
                    lblTitle.Content = value;
                }
            }
        }
        public string FlowNodeType { get; set; }

        [Category("节点状态")]
        public Color LightColor
        {
            get
            {
                var brush = lblLED.Foreground as SolidColorBrush;
                return brush != null ? brush.Color : Colors.Transparent; // 默认返回透明色
            }
            set
            {
                lblLED.Foreground = new SolidColorBrush(value);
            }
        }

        public string NodeID { get; set; } // 节点编号

        public List<string> PreviousNodes { get; set; } = new List<string>();
        public List<string> NextNodes { get; set; } = new List<string>();


        public IModule FlowNodeTool { get; set; }

        public FlowNode()
        {
            InitializeComponent();
        }

        public FlowNode(string flowNodeType, string flowname)
        {
            InitializeComponent();
            FlowNodeType = flowNodeType;
            FlowName = flowname;
        }

        private void FlowNode_Loaded(object sender, RoutedEventArgs e)
        {
            // 初始化节点ID
            NodeID = Guid.NewGuid().ToString();
        }

        private void FlowNode_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            //保存当前节点数据
            switch (this.FlowNodeType)
            {
                case "圆查找":
                    CircleFind circleFind = new CircleFind();
                    CMvdImage _TrainImage = new CMvdImage();
                    //_TrainImage.InitImage("E:\\pictures\\output_gray_image.jpg", VisionDesigner.MVD_PIXEL_FORMAT.MVD_PIXEL_MONO_08);
                    _TrainImage.InitImage("D:\\Arobot\\作业\\DSC03543.JPG", VisionDesigner.MVD_PIXEL_FORMAT.MVD_PIXEL_MONO_08);
                    circleFind.InputData = _TrainImage;
                    circleFind.ShowDialog();
                    //(CircleFind)FlowNodeTool.InputData = _TrainImage;
                    //(CircleFind)FlowNodeTool.ShowDialog();
                    break;
                case "加载图像":
                    ImageLoad imageLoad = new ImageLoad();
                    imageLoad.ShowDialog();
                    break;
            }
        }


    }
}
